package pt.fct.mpc.lastfm.geo;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class LastfmGeoEventsOverlay
	extends ItemizedOverlay<OverlayItem>
{
	private static final String TAG = "Last.fm Geo Events Overlay";
	private ArrayList<OverlayItem> items_array = 
		new ArrayList<OverlayItem>();
	
	private Context context;
	
	public LastfmGeoEventsOverlay(Context context, Drawable marker)
	{
		super(boundCenterBottom(marker));
		this.context = context;
	}

	@Override
	protected OverlayItem createItem(int i)
	{
		Log.d(TAG, "Creating item: position = "+i
			+", value = "+this.items_array.get(i));
		return this.items_array.get(i);
	}

	@Override
	public int size()
	{
		return this.items_array.size();
	}
	
	public void addToOverlay(OverlayItem item)
	{
		this.items_array.add(item);
		populate();
	}
	
	@Override
	protected boolean onTap(int index)
	{
		super.onTap(index);
		
		OverlayItem item = this.items_array.get(index);
		AlertDialog.Builder dialog = new AlertDialog.Builder(context);
		dialog.setTitle(item.getTitle());
		dialog.setMessage(item.getSnippet());
		dialog.show();
		return true;
	}
}
